import actionTypes from '../actions/actionTypes'
const initState = {
    isLoading: false,
    list: [
        {
            id: 1,
            desc: '我想要我想要的生活，可是现在啥都没有啊，这可咋办啊',
            hasRead: false
        },
        {
            id: 2,
            desc: '我想要我想要的生活，可是现在啥都没有啊，这可咋办啊',
            hasRead: true
        }
        
    ]
}

export default(state=initState, action) => {
    switch (action.type){
        case actionTypes.START_MARK_NOTIFITION_HAS_READ:
            return {
                ...state,
                isLoading: true
            }
        case actionTypes.FINISH_MARK_NOTIFITION_HAS_READ:
            return {
                ...state,
                isLoading: false
            }
            
        case actionTypes.MARK_NOTIFICATION_BY_ID:
            const newList = state.list.map(item=>
                {
                    if(item.id===action.payload.id){
                        item.hasRead = true
                    }
                    return item
                })
                return {
                    ...state, 
                    list: newList
                    
                }
        case actionTypes.MARK_ALL_NOTIFICATION_BY_HASREAD:
            return {
                ...state,
                list: state.list.map(item=>{
                    item.hasRead=true
                    return item
                })
            }
            case actionTypes.GET_NOTIFICATIONLIST:
                return {
                    ...state,
                    list: action.payload.list
                }
        default:
           return state
    }
}